{% extends 'sys_manage.html' %}
{% block table %}
    {#    {% if cate == '12' %}#}
    <div class="layui-row">
        <div class="layui-col-md6">·
            <span>状态：</span>
            <span class="layui-breadcrumb" lay-separator="|" id="status">
                  <a href="/user/message/2/" status="2">全部消息</a>
                  <a href="/user/message/0/" status="0">新消息</a>
                  <a href="/user/message/1/" status="1">已读消息</a>
                </span>
        </div>
    </div>
    <table class="layui-table"
           lay-data="{url:'/user/message/3/?status={{ cate }}',limit: 10,text:{none:'当前暂无信息'}, page:true, id:'message_table'}"
           lay-filter="message">
        <thead>
        <tr>
            <th lay-data="{field: 'id', width: 80, sort: true, fixed: true}">序号</th>
            <th lay-data="{field: 'title', templet: '#titleTpl'}">标题</th>
            <th lay-data="{field: 'push_time',  width: 180}">时间</th>
            <th lay-data="{fixed: 'right',  width: 82, align: 'center', toolbar: '#operate_bar'}">操作</th>
        </tr>
        </thead>
    </table>
    <script type="text/html" id="operate_bar">
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"
           data-type="auto">删除</a>
    </script>
{% endblock %}

{% block customjs %}
    {{ block.super }}
    <script type="text/html" id="titleTpl">
        <a href="/user/message/detail/{% verbatim %}{{ d.real_id }}{% endverbatim %}/" class="layui-table-link">{% verbatim %}{{
            d.title }}{% endverbatim %}</a>
        {% verbatim %}
        {{#  if(d.status == 0){ }}
        <span class="layui-badge-dot"></span>
        {{#  } }}
        {% endverbatim %}
    </script>
    <script>
        $(function () {
            $('#message').addClass('layui-this');
            $('#status a[status="{{ cate }}"]').addClass('status-this');
{#            $('#message').parent().addClass('layui-nav-itemed');#}
{#            $('#message a[status="{{ cate }}"]').addClass('layui-this').css({color: '#fff'});#}
        });
        layui.use(['table'], function () {
            var table = layui.table;
            var layer = layui.layer;

            //监听操作选项的工具条事件tool后跟的message是table标签的lay-filter
            table.on('tool(message)', function (obj) {
                var data = obj.data;
                if (obj.event === 'del') {
                    //向服务端发送请求，服务器修改此条信息的状态
                    layer.confirm('真的要删除么？', function (index) {
                        $.ajax({
                            type: 'delete',
                            url: '/user/message/',
                            data: {real_id: data.real_id},
                            dataType: 'json',
                            success: function (data) {
                                if (data.code === 0) {
                                    layer.msg(data.msg, {
                                        icon: 6, time: 2000, end: function () {
                                            location.reload()
                                        }
                                    });
                                } else {
                                    layer.alert(data.msg)
                                }
                            }
                        }
                    )
                    });
                }
            });
        });
    </script>
{% endblock %}
